<template>
	<view class="main" :style="{paddingBottom:(getSafeBottom )+'px'}">
		<navbar title="培训机构"></navbar>

		<view class="content" :style="{paddingTop:(getStateHeight + getNavbar  ) + 'px'}">
			<view class="item-box">
				<view class="item" v-for="item in dataList" :key="item.id"   @click="toDetail(item)">
					<view class="item-title">
						{{item.title}}
					</view>
					<view class="item-data">
						<view class="item-line">
							<view class="item-line-icon">
								<image :src="imgUrl + 'telIcon.png'" mode="widthFix"></image>
							</view>
							<view class="item-line-label">
								联系方式：{{item.tel}}
							</view>
							<!-- <view class="item-line-button" @click.stop="copy(item.tel)">
								点击获取
							</view> -->
						</view>
						<view class="item-line">
							<view class="item-line-icon">
								<image :src="imgUrl + 'addrIcon.png'" mode="widthFix"></image>
							</view>
							<view class="item-line-label">
								地址：{{item.addr}}
							</view>
						</view>
					</view>
					<view class="item-end">
						<view class="item-button" :class="{'success':item.status==1}">
							查看详情
						</view>
					</view>
					<view class="item-hr"></view>
				</view>
			</view>
		</view>
		<view class="main-bj">

		</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapState
	} from 'vuex';
	import Navbar from '@/components/Navbar.vue'
	import {
		getServeList
	} from "@/core/web-api/qiuzhiduan.js"
	export default {
		data() {
			return {
				dataList: [],
				page: {
					current: 1,
					limit: 10,
				}
			}
		},
		components: {
			Navbar
		},
		methods: {
			toDetail(item){
				uni.navigateTo({
					url:"/pages/web/service/qiuzhiduan/peixunjigouDetail?id=" + item.id
				})
			},
			/**
			 * 加载数据
			 */
			getList() {
				getServeList({
					...this.page,
					cataName:"培训机构"
				}).then(res => {
					if (res.code == 20000) {
						const {
							total,
							list
						} = res.data;
						if (this.page.current == 1) {
							this.dataList = list;
						} else {
							this.dataList.push(...list);
						}
						this.total = total;
					}
				})
			},

			/**
			 * 分页加载
			 */
			pageData() {
				if (this.total == this.dataList.length) return;
				this.page.current++;
				this.getList()
			},
			copy(text) {
				uni.setClipboardData({
					data: text,
					success() {
						uni.showToast({
							title: "复制成功",
							icon: "success"
						})
					},
					fail(err) {
						console.log(err)
						uni.showToast({
							title: "复制失败",
							icon: "none"
						})
					}
				})
			},
		},
		onReachBottom() {
			this.pageData();
		},
		computed: {
			...mapGetters(['getNavbar', 'getStateHeight', 'getSafeBottom']),
			...mapState(['imgUrl'])
		},
		created() {
			this.getList()
		}
	}
</script>

<style scoped lang="less">
	.main {
		width: 100%;
		padding: 0 30upx;
		box-sizing: border-box;

		&-bj {
			width: 100%;
			height: 50vh;
			position: fixed;
			left: 0;
			top: 0;
			z-index: -1;
			background: linear-gradient(to bottom, #bdccfb, #f5f5f5);
		}
	}

	.content {
		margin-top: 30upx;
	}

	.item {
		padding: 20upx;
		padding-bottom: 30upx;
		box-sizing: border-box;
		background-color: #fff;
		border-radius: 8upx;
		position: relative;
		margin-bottom: 50upx;

		&:last-child {
			margin-bottom: 0;
		}

		&-hr {
			display: block;
			width: 4upx;
			height: 32upx;
			position: absolute;
			left: 0upx;
			top: 30upx;
			background-color: #0180ff;
		}

		&-box {
			width: 100%;
		}

		&-title {
			font-size: 34upx;
			color: #000000;
			font-weight: bold;
			padding-left: 10upx;
			padding-bottom: 20upx;
			border-bottom: 2upx solid #f6f6f6;
		}

		&-data {
			padding-top: 30upx;
		}

		&-line {
			display: flex;
			align-items: center;
			margin-bottom: 15upx;

			&:last-child {
				margin-bottom: 0;
			}

			&-icon {
				width: 18upx;
				margin-right: 10upx;

				image {
					width: 18upx;
				}
			}

			&-label {
				font-size: 26upx;
				color: #666666;
				display: flex;
				text{
					font-size: 26upx;
					color: #666666;
					flex:1;
				}
			}

			&-button {
				margin-left: 20upx;
				font-size: 26upx;
				color: #0180ff;
			}

		}

		&-button {
			width: 150upx;
			height: 56upx;
			border-radius: 10upx;
			text-align: center;
			line-height: 56upx;
			background-color: #f6f7f9;
			font-size: 24upx;
			color: #000000;

			&.success {
				background-color: #0180ff;
				color: #fff;
			}
		}

		&-end {
			display: flex;
			justify-content: flex-end;
		}
	}
</style>